import React from 'react';
import Table from './../common/table';
import {selfPost} from './../../api';
// import { Table } from 'antd';
//import "antd/dist/antd.css";

export default class SourceInfo extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
    	dataSource: null
    }
  }

  componentWillMount() {
  	selfPost().then(res=>{
      if(res.content.length>0) {
  	  	this.setState({
  	   	  dataSource: res.content
  		  });
      } else {
        this.setState({
          dataSource: null
        });
      }
  	});
  }

  render() {
  	const columns = [
  		{
  			name:'index',
  			title:'序号',
  			width: 120,
  		}, 
  		{
  			name:'title',
  			title:'主题'
  		},
  		{
  			name:'context',
  			title:'内容',
  			width:'300',
        formatter: function(row,index,value) {
          return <span dangerouslySetInnerHTML={{__html: value}}></span>
        }
  		},
  		{
  			name:'createTime',
  			title:'发布时间',
  			width:'150',
  			sorted:true
  		},
  		{
  			name: 'handle',
  			title:'操作',
  			formatter: function(row,index) {
  				return <button className="btn btn-success">查看</button>
  			}
  		}
  	];

    return (
      <div className="source_box_body">
      	<Table 
    	  tableTitle="历史发帖"
      	  columns={columns} 
          dataSource={this.state.dataSource}
          className="sample"
        />
      </div>
    );
  }
}